export const usernameVf = [
  { required: true, message: '请输入用户名', trigger: 'blur' },
  { min: 3, max: 10, message: '用户名长度在 3 到 10 个字符', trigger: 'blur' }
]

export const passwordVf = [
  { required: true, message: '请输入密码', trigger: 'blur' },
  { min: 6, max: 15, message: '密码长度在 6 到 15 个字符', trigger: 'blur' }
]

export const  emailVf = function () {
  let checkEmail = (rule, value, callback) => {
    const mailReg = /^([a-zA-Z0-9_-])+@([a-zA-Z0-9_-])+(.[a-zA-Z0-9_-])+/
    if (!value) {
      return callback(new Error('邮箱不能为空'))
    }
    setTimeout(() => {
      if (mailReg.test(value)) {
        callback()
      } else {
        callback(new Error('请输入正确的邮箱格式'))
      }
    }, 100)
  }
  return [
    { required: true, message: '请输入邮箱', trigger: 'blur' },
    { validator: checkEmail, trigger: 'blur' }
  ]
}()

export const mobileVf = function() {
  var checkPhone = (rule, value, callback) => {
    const phoneReg = /^1[3|4|5|7|8][0-9]{9}$/
      if (!value) {
        return callback(new Error('电话号码不能为空'))
      }
      setTimeout(() => {
        // Number.isInteger是es6验证数字是否为整数的方法,但是我实际用的时候输入的数字总是识别成字符串
        // 所以我就在前面加了一个+实现隐式转换

        if (!Number.isInteger(+value)) {
          callback(new Error('请输入数字值'))
        } else {
          if (phoneReg.test(value)) {
            callback()
          } else {
            callback(new Error('电话号码格式不正确'))
          }
        }
      }, 100)
    }
    return [
      { required: true, message: '请输入手机', trigger: 'blur' },
      { validator: checkPhone, trigger: 'blur' }
    ]
}()

export const rolenameVf = [
  { required: true, message: '请输入角色名称', trigger: 'blur' },
  { min: 3, max: 10, message: '角色名称长度在 3 到 10 个字符', trigger: 'blur' }
]

export const roledescVf = [
  { required: true, message: '请输入角色描述', trigger: 'blur' },
  { min: 3, max: 10, message: '角色描述长度在 3 到 10 个字符', trigger: 'blur' }
]

export const catnameVf = [
  { required: true, message: '请输入分类名称', trigger: 'blur' },
  { min: 3, max: 10, message: '分类名称长度在 3 到 10 个字符', trigger: 'blur' }
]

export const attrnameVf = [
  { required: true, message: '请输入参数名称', trigger: 'blur' },
  { min: 2, max: 10, message: '参数名称长度在 2 到 10 个字符', trigger: 'blur' }
]

export const goodsnameVf = [
  { required: true, message: '请输入商品名称', trigger: 'blur' },
  { min: 3, max: 60, message: '商品名称长度在 3 到 60 个字符', trigger: 'blur' }
]

export const goodspriceVf = [
  { required: true, message: '请输入商品价格', trigger: 'blur' }
]

export const goodsweightVf = [
  { required: true, message: '请输入商品重量', trigger: 'blur' }
]

export const goodsnumberVf = [
  { required: true, message: '请输入商品数量', trigger: 'blur' }
]

export const goodscatVf = [
  { required: true, message: '请选择商品分类', trigger: 'blur' }
]

export const address1Vf = [
  { required: true, message: '请选择省市区', trigger: 'blur' }
]

export const address2Vf = [
  { required: true, message: '请输入详细地址', trigger: 'blur' },
  { min: 3, max: 30, message: '详细地址长度在 3 到 30 个字符', trigger: 'blur' }
]